package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.Unit;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

@Mapper
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/mapper/UnitMapper.class */
public interface UnitMapper {
    @Delete({"delete from unit where id = #{id,jdbcType=INTEGER}"})
    int deleteById(Integer num);

    @Select({"<script>"+
            "select count(*) from unit <where>  <if test='type != null '>and type = #{type} </if>" +
            "<if test='unitNum != null '>and unit_num = #{unitNum} </if>" +
            "<if test='unitName != null '>and unit_name = #{unitName} </if>" +
            "</where></script>"})
    Integer findUnitByTypeAndUnit(@Param("type")String type,@Param("unitNum") String unitNum,@Param("unitName") String unitName);

    @Select({"select u.id, u.type, u.unit_num, u.company_id, c.company_name as unit_name from unit u left join company c on u.company_id = c.id "})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_num", property = "unitNum", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_name", property = "unitName", jdbcType = JdbcType.VARCHAR), @Result(column = "company_id", property = "companyId", jdbcType = JdbcType.INTEGER)})
    List<Unit> getAdd();

    @Insert({"insert into unit (type, unit_num, unit_name, company_id) "+
            "values (#{type,jdbcType=VARCHAR}, #{unitNum,jdbcType=VARCHAR}, "+
            "#{unitName,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER})"})
    int add(Unit unit);

    @Select({"<script>", "select u.id, u.type, u.unit_num, u.company_id, u.unit_name from unit u left join company c on u.company_id = c.id <where><if test='type != null '>and type = #{type} </if></where></script>"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_num", property = "unitNum", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_name", property = "unitName", jdbcType = JdbcType.VARCHAR), @Result(column = "company_id", property = "companyId", jdbcType = JdbcType.INTEGER)})
    List<Unit> findAll(String str);

    @Select({"select * from unit u where type = #{type,jdbcType=VARCHAR} order by unit_num "})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_num", property = "unitNum", jdbcType = JdbcType.VARCHAR), @Result(column = "unit_name", property = "unitName", jdbcType = JdbcType.VARCHAR)})
    List<Unit> findByType(String str);

    @Update({"<script>update unit <set><if test='companyId != null '> company_id=#{companyId},</if><if test='type != null and type.length &gt; 0'> type=#{type},</if><if test='unitNum != null and unitNum.length &gt; 0'> unit_num=#{unitNum},</if><if test='unitName != null and unitName.length &gt; 0'> unit_name=#{unitName},</if><if test='companyId != null '> company_id=#{companyId}</if></set> where id = #{id}</script>"})
    int updateById(Unit unit);

    @Select({"select u.unit_num from unit u left join company c on u.company_id = c.id where c.company_name = #{unitName,jdbcType=VARCHAR} and u.type = #{type,jdbcType=VARCHAR}"})
    @Results({@Result(property = "unitNum", column = "unit_num")})
    String findOneByName(@Param("type") String str, @Param("unitName") String str2);

    @Select({"select unit_name from unit  where unit_num = #{unitNum,jdbcType=VARCHAR} and type = #{type,jdbcType=VARCHAR}"})
    String findOneByNum(@Param("type") String str, @Param("unitNum") String str2);
}